home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / clang / netclb23.zip / EXAMPLES.EXE / ULIST.C < prev    next >
C/C++ Source or Header  |  1994-05-20  |  4KB  |  117 lines

  1. /***************************************************************************/
  2. /* File:             ULIST.C                                               */
  3. /*                                                                         */
  4. /* Function:         List all users that are currently logged into the     */
  5. /*                   default server, and some useful stats (only if        */
  6. /*                   calling user has console operator rights).            */
  7. /*                                                                         */
  8. /* Usage:            ulist                                                 */
  9. /*                                                                         */
  10. /* Functions Called: GetPreferredConnectionID                              */
  11. /*                   GetDefaultConnectionID                                */
  12. /*                   SetPreferredConnectionID                              */
  13. /*                   GetPrimaryConnectionID                                */
  14. /*                   ISShellLoaded                                         */
  15. /*                   GetConnectionNumber                                   */
  16. /*                   GetConnectionInformation                              */
  17. /*                   GetConnectionsUsageStatistics                         */
  18. /*                                                                         */
  19. /***************************************************************************/
  20. #include <conio.h>
  21. #include <dos.h>
  22.  
  23. #ifndef TURBOC
  24. #include <search.h>
  25. #endif
  26.  
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include <time.h>
  31.  
  32. #include "netware.h"
  33.  
  34. #define   FALSE   0
  35. #define   TRUE    (!FALSE)
  36.  
  37. static char *days_of_week[] = { "Sun" , "Mon" , "Tue" ,
  38.                                 "Wed" , "Thu" , "Fri" ,
  39.                                 "Sat" };
  40.  
  41. /**********************************************************************/
  42.  
  43. void main()
  44. {
  45. unsigned int    station;
  46. long object_id;
  47. word object_type;
  48. char object_name[OBJECT_LENGTH];
  49. char logintime[7];
  50. int thisone;
  51. long systemelapsedtime;
  52. double bytesread,byteswritten;
  53. long totalrequestpackets;
  54. char c;
  55. int prefserver;
  56. int thisserver;
  57.  
  58.    if (IsShellLoaded() != SUCCESS)
  59.    {
  60.       printf("*** No netware shell loaded ***\n");
  61.       exit(255);
  62.    }
  63.  
  64.    if ((prefserver = GetPreferredConnectionID()) == 0)
  65.    {
  66.       if ((thisserver = GetDefaultConnectionID()) == 0)
  67.          thisserver = GetPrimaryConnectionID();
  68.       SetPreferredConnectionID( thisserver );
  69.    }
  70.    else
  71.       thisserver = prefserver;
  72.  
  73.    if( ( thisone=GetConnectionNumber() ) == 0)
  74.    {
  75.       printf("*** No connection number found ***\n");
  76.       if (thisserver != prefserver)   /* reset preferred server */
  77.          SetPreferredConnectionID( prefserver );
  78.       exit(255);
  79.    }
  80.  
  81.    printf("                      ---Login----");
  82.    printf("      -----file bytes------   request\n");
  83.    printf("conn User Name        day     time");
  84.    printf("      read          written   packets\n");
  85.    printf("==================================");
  86.    printf("      ===============================\n");
  87.    
  88.    /* Here, we loop through all the possible stations (connections).  */
  89.  
  90.    for (station=1; station<100; station++)
  91.    {
  92.          GetConnectionInformation( station , object_name,
  93.                                    &object_type,&object_id,
  94.                                    (byte *)logintime);
  95.          if (object_name[0]!=0)
  96.          {
  97.             if (thisone==station) c='*'; else c=' ';
  98.             printf(" %2u %c%-16s %-3s %02d:%02d:%02d",
  99.                    station , c , object_name ,
  100.                    days_of_week[ logintime[6] ],
  101.                    logintime[3],logintime[4],logintime[5] );
  102.             if ( GetConnectionsUsageStatistics( station,
  103.                                                 &systemelapsedtime ,
  104.                                                 &bytesread,&byteswritten,
  105.                                                 &totalrequestpackets ) == 0)
  106.                    printf("      %-10.0f %10.0f   %7ld\n",
  107.                            bytesread,byteswritten,totalrequestpackets);
  108.             else
  109.                    printf("\n");
  110.             
  111.          }
  112.    }
  113.  
  114.    if (thisserver != prefserver)   /* reset preferred server */
  115.       SetPreferredConnectionID( prefserver );
  116. }
  117.